package com.travelgroup.controller;

import cn.dev33.satoken.util.SaResult;
import com.travelgroup.domain.dto.LoginDTO;
import com.travelgroup.domain.dto.UserDTO;
import com.travelgroup.domain.entity.Notification;
import com.travelgroup.exception.R;
import com.travelgroup.service.INotificationService;
import com.travelgroup.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Tag(name = "用户模块")
public class UserController {
    @Resource
    private IUserService userService;
    @Resource
    private INotificationService notificationService;

    @PostMapping("/login/password")
    @Operation(summary = "密码登录")
    public R<SaResult> loginByPassword(@RequestBody LoginDTO loginDTO) {
        return userService.loginByPassword(loginDTO);
    }

    @PostMapping("/login/email")
    @Operation(summary = "验证码登录/注册")
    public R<SaResult> loginByCode(@RequestBody LoginDTO loginDTO) {
        return userService.loginByCode(loginDTO);
    }

    @PostMapping("/send")
    @Operation(summary = "发送验证码")
    public R<String> sendCode(@RequestBody LoginDTO loginDTO) {
        return userService.sendCode(loginDTO.getEmail());
    }

    @PostMapping("/verify/code")
    @Operation(summary = "验证码二级认证")
    public R<String> verifyCode(@RequestBody LoginDTO loginDTO) {
        return userService.verifyCode(loginDTO);
    }

    @PostMapping("/verify/password")
    @Operation(summary = "密码二级认证")
    public R<String> verifyPassword(@RequestBody LoginDTO loginDTO) {
        return userService.verifyPassword(loginDTO);
    }

    @PostMapping("/reset/password")
    @Operation(summary = "重置密码")
    public R<String> resetPassword(@RequestBody LoginDTO loginDTO) {
        return userService.resetPassword(loginDTO);
    }

    @PostMapping("/set/userInfo")
    @Operation(summary = "设置用户个人信息")
    public R<String> setUserInfo(@RequestBody UserDTO userDTO) {
        return userService.updateUserInfo(userDTO);
    }

    @GetMapping("/query/user/{id}")
    @Operation(summary = "获取用户信息")
    public R<UserDTO> queryUserById(@PathVariable Long id) {
        return userService.queryById(id);
    }

    @GetMapping("/query/notification/me")
    @Operation(summary = "获取用户消息")
    public R<List<Notification>> queryMyNotification() {
        return notificationService.queryMyNotifications();
    }

    @GetMapping("/query/notification/{id}")
    public R<Notification> queryNotificationById(@PathVariable Long id) {
        return notificationService.queryNotificationById(id);
    }

}
